package com.factory.dao;

import com.factory.entity.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface EmployeeDao {

    // 插入员工
    @Insert("INSERT INTO employee(emp_name, gender, age, position, department, salary, " +
            "hire_date, email, phone, address) " +
            "VALUES(#{empName}, #{gender}, #{age}, #{position}, #{department}, #{salary}, " +
            "#{hireDate}, #{email}, #{phone}, #{address})")
    @Options(useGeneratedKeys = true, keyProperty = "empId")
    int insertEmployee(Employee employee);

    // 根据ID删除员工
    @Delete("DELETE FROM employee WHERE emp_id = #{empId}")
    int deleteEmployee(Integer empId);

    // 更新员工信息
    @Update("UPDATE employee SET emp_name=#{empName}, gender=#{gender}, age=#{age}, " +
            "position=#{position}, department=#{department}, salary=#{salary}, " +
            "hire_date=#{hireDate}, email=#{email}, phone=#{phone}, address=#{address} " +
            "WHERE emp_id=#{empId}")
    int updateEmployee(Employee employee);

    // 根据ID查询员工
    @Select("SELECT * FROM employee WHERE emp_id = #{empId}")
    Employee selectEmployeeById(Integer empId);

    // 查询所有员工
    @Select("SELECT * FROM employee")
    List<Employee> selectAllEmployees();

    // 根据姓名查询员工
    @Select("SELECT * FROM employee WHERE emp_name LIKE CONCAT('%', #{empName}, '%')")
    List<Employee> selectEmployeesByName(String empName);

    // 根据部门查询员工
    @Select("SELECT * FROM employee WHERE department = #{department}")
    List<Employee> selectEmployeesByDepartment(String department);

    // 根据职位查询员工
    @Select("SELECT * FROM employee WHERE position = #{position}")
    List<Employee> selectEmployeesByPosition(String position);
}